# -*- coding: utf-8 -*-
""" 
@author: ertao.xyz
@create: 2021-12-16 11:16
@description: 
"""
from tortoise import fields
from tortoise.models import Model

from core.model import AbstractBaseModel, TimestampMixin


class Weixinmp(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    name = fields.CharField(max_length=32, description='公众号名称')
    appId = fields.CharField(max_length=32, description='AppId', unique=True)
    appSecret = fields.CharField(max_length=32, description='AppSecret')
    token = fields.CharField(max_length=32, null=True, default=None, description='Token')
    encodingAESKey = fields.CharField(max_length=43, null=True, default=None, description='EncodingAESKey')
    # templateMsgId = fields.CharField(max_length=43, null=True, default=None, description='模板消息ID')
    serverUrl = fields.CharField(max_length=256, description='服务器地址URL')
    dingcanTongzhi = fields.CharField(max_length=32, null=True, default=None, description='订餐通知模板ID')
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.name

    class Meta:
        table = "wechatmpSetting"
        table_description = "公众号设置"
        ordering = ["-created_at"]


class Taobao(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    appId = fields.CharField(max_length=32, description='AppId', unique=True)
    appSecret = fields.CharField(max_length=32, description='AppSecret')
    pid = fields.CharField(max_length=128, description='PID')
    adzone_id = fields.CharField(max_length=32, description='广告位id')
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.appId

    class Meta:
        table = "taobaoSetting"
        table_description = "淘宝设置"
        ordering = ["-created_at"]


class Pinduoduo(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    clientId = fields.CharField(max_length=32, description='clientId', unique=True)
    clientSecret = fields.CharField(max_length=32, description='clientSecret')
    pid = fields.CharField(max_length=128, description='PID')
    accessToken = fields.CharField(max_length=32, description='accessToken', null=True)
    exp_date = fields.DatetimeField(description='授权过期时间', null=True)
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.clientId

    class Meta:
        table = "pddSetting"
        table_description = "拼多多设置"
        ordering = ["-created_at"]


class Jingdong(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    unionId = fields.CharField(max_length=32, description='京东联盟ID')
    appKey = fields.CharField(max_length=64, description='appKey')
    appSecret = fields.CharField(max_length=64, description='appSecret')
    key = fields.CharField(max_length=256, description='授权key')
    exp_date = fields.DateField(description='授权Key过期日期')
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.unionId

    class Meta:
        table = "jingdongSetting"
        table_description = "京东设置"
        ordering = ["-created_at"]


class Meituan(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    sid = fields.CharField(max_length=32, description='美团联盟SID', null=True)
    appKey = fields.CharField(max_length=64, description='美团联盟appKey', null=True)
    appSecret = fields.CharField(max_length=64, description='美团联盟appSecret')
    pubAppkey = fields.CharField(max_length=256, description='美团分销appkey')
    utmSource = fields.CharField(max_length=256, description='美团分销utmSource')
    pid = fields.CharField(max_length=256, description='美团分销pid')
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.sid

    class Meta:
        table = "meituanSetting"
        table_description = "美团设置"
        ordering = ["-created_at"]


class Dataoke(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者',)
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    appKey = fields.CharField(max_length=64, description='appKey', null=True)
    appSecret = fields.CharField(max_length=64, description='appSecret')
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.appKey

    class Meta:
        table = "dataokeSetting"
        table_description = "大淘客设置"
        ordering = ["-created_at"]


class Vip(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    accessToken = fields.CharField(max_length=32, description='美团联盟SID', null=True)
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.accessToken

    class Meta:
        table = "vipSetting"
        table_description = "唯品会设置"
        ordering = ["-created_at"]


class Fenxiao(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    wechatMini = fields.OneToOneField('models.WechatMini', description='所属小程序ID')
    accessToken = fields.CharField(max_length=32, description='美团联盟SID', null=True)
    zigou = fields.DecimalField(description='自购比例', max_digits=5, decimal_places=2)
    one = fields.DecimalField(description='自购比例', max_digits=5, decimal_places=2)
    two = fields.DecimalField(description='自购比例', max_digits=5, decimal_places=2)
    three = fields.DecimalField(description='自购比例', max_digits=5, decimal_places=2)
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.accessToken

    class Meta:
        table = "fenxiaoSetting"
        table_description = "分销设置"
        ordering = ["-created_at"]
